package com.smile.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smile.common.to.es.SkuEsModel;
import com.smile.common.utils.PageUtils;
import com.smile.common.utils.Query;
import com.smile.product.dao.SpuInfoDao;
import com.smile.product.entity.SkuInfoEntity;
import com.smile.product.entity.SpuInfoEntity;
import com.smile.product.service.SkuInfoService;
import com.smile.product.service.SpuInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("spuInfoService")
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
    @Autowired
    SkuInfoService skuInfoService;

    @Override
    public void up(Long spuId) {
        List<SkuInfoEntity> skuInfoEntities = new ArrayList<>();
        SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
        List<SkuInfoEntity> skus = skuInfoService.getSkuBySpuId(spuId);
        skus.stream().map(sku ->{
            SkuEsModel skuEsModel = new SkuEsModel();
            BeanUtils.copyProperties(sku,skuEsModel);
            skuEsModel.setSkuPrice(sku.getPrice());
            skuEsModel.setSkuImg(sku.getSkuDefaultImg());

            //TODO 1.发送远程调用库存系统中是否有库存
            //TODO 2.热度评分
            //TODO 3.查询品牌和分类的名字信息
            return skuEsModel;
        }).collect(Collectors.toList());

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpuInfoEntity> page = this.page(
                new Query<SpuInfoEntity>().getPage(params),
                new QueryWrapper<SpuInfoEntity>()
        );

        return new PageUtils(page);
    }

}